﻿@model Wiwi.ViewModels.SearchView

@{
    ViewBag.Title = "Search WiWi's";
}
<script type="text/javascript" >
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var lastdate = month + "," + currentTime.getDate() + "," + currentTime.getFullYear() + "," + currentTime.getHours() + "," + currentTime.getMinutes() + "," + currentTime.getSeconds();
    $(document).ready(function () {
        $('#btnTopCounter').hide();
        UpdateData();
    });

    function UpdateData() {
        var Searchterm = $('#hidSearchCounters').val();
        if(Searchterm!="")
        {
            $.ajax({
                url: "/Want/SearchCount",
                dataType: 'json',
                type: 'GET',
                data: 'DT=' + lastdate + '&Term=' + Searchterm,
                contentType: 'application/json; charset=utf-8',
                processData: true,
                success: function (data) {
                    if (data > 0) {
                        var currentFunc = new Date()
                        var monthFunc = currentFunc.getMonth() + 1
                        lastdate = monthFunc + "," + currentFunc.getDate() + "," + currentFunc.getFullYear() + "," + currentFunc.getHours() + "," + currentFunc.getMinutes() + "," + currentFunc.getSeconds();
                        $('#btnTopCounter').val(data.toString() + " new Wants");
                        $('#btnTopCounter').show();
                    }
                    else {
                        $('#btnTopCounter').hide();
                    }
                }
            });
        setTimeout("UpdateData()", 15000);
        }
    }
</script>

 <div class="grid_8 box-shadow margin-top">
   
    <h4 class="tabbed xWide">Search Results</h4> 

     @using (Html.BeginForm("Search", "Want"))
     {
        <input type ="hidden" id="hidSearchCounters" name="hidSearchCounters" value ="@Model.SearchTerm" />
        <input type ="submit" id="btnTopCounter" value="tst" />
     }

     @if (Model.Searches.Count > 0) {

       foreach (var wnt in Model.Searches) {
           
             @Html.Partial("~/Views/Shared/_WantControl_search.cshtml", wnt)
              <hr />  
       }


     }
     else
     {
         
          <p class="serif-it margin-left">Sorry! There currently are no wants for this keyword.</p>
        
         <hr />
          
     }
          
 
          

      
      @if (Request.IsAuthenticated)
      {

          if (Model.Searches.Count > 0)
          {
              using (Html.BeginForm("SaveSearch", "Want", FormMethod.Post))
              {
                    @Html.HiddenFor(m => m.SearchTerm)
                    @Html.HiddenFor(m => m.SearchType)                                 
                    <input type ="hidden" name="search-name" id="search-name"/>  
                    <p class="green click"><input type="submit" value="Save Search" id="SaveSearch" class="button-m" style="margin-left: 170px;" /></p>
		            
              }
          }
       
      }
    </div>

    
